package com.jj.conterllor;

import com.jj.entity.role;
import com.jj.service.Roleservice;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/r")
public class Rolecontroller {

    @Resource
    private Roleservice roleservice;

    //查询-----------------------------------
    @RequestMapping("role")
    public String selectRoleAll(ModelMap map){
        List<role> roles = roleservice.selectRoleAll();
        map.addAttribute("roles",roles);
        return"rlselect";
    }
    //添加--------------------------------------
    @RequestMapping("a")
    public String dd(){
        return "rlinsert";
    }
    @RequestMapping("rlinsert")
    public String insertadd(role tj){
        roleservice.insertadd(tj);
        return "forward:role";
    }
    //删除------------------------------------
    @RequestMapping("delete")
    public String shan(int role_id){
        roleservice.deletesc(role_id);
        return "forward:role";
    }
    //修改----------------------------------
    @RequestMapping("xg")
    public String x(Model model, int role_id){
        model.addAttribute("rid",role_id);
        return "rlupdate";
    }
    @RequestMapping("rlupdate")
    public String updatexg(role xg){
        role re = new role();
        re.setRole_name(xg.getRole_name());
        re.setRole_id(xg.getRole_id());
        roleservice.updatexg(re);
        return "forward:role";
    }

}
